<template>
	<view class="main-content pageBg">
		<custom-nav-bar title="推荐"></custom-nav-bar>
		<view class="banner">
			<swiper indicator-active-color="#c4c4c4" indicator-dots indicator-color="#999" autoplay circular>
				<swiper-item v-for="item in bannerList" :key="item._id">
					<!--  跳到别的小程序 ..-->
					<navigator v-if="item.target == 'miniProgram'" :url="item.url" class="like" target="miniProgram"
						:app-id="item.appid">
						<image :src="item.picurl" mode="aspectFill"></image>
					</navigator>

					<navigator v-else :url="`/pages/classList/classList?${item.url}`" class="like">
						<image :src="item.picurl" mode="widthFix"></image>

					</navigator>
				</swiper-item>
			</swiper>
		</view>
		<view class="notice">
			<view class="left">
				<uni-icons color="#28B389" size="20" type="sound-filled"></uni-icons>
				<text class="text-notice">公告</text>
			</view>
			<view class="center">
				<swiper autoplay vertical circular duration="500" interval="2000">
					<swiper-item>
						<navigator url="/pages/notice/detail">欢迎关注浮生一梦圈子公众号，获取UP主浮生一梦的最新状态</navigator>
					</swiper-item>
					<swiper-item>
						<navigator url="/pages/notice/notice">智慧视图壁纸，版权公告</navigator>
					</swiper-item>
				</swiper>
			</view>
			<view class="right">
				<uni-icons type="right" size="16"></uni-icons>
			</view>
		</view>
		<view class="select">
			<commonTitle>
				<template #name>
					<text>每日推荐</text>
				</template>
				<template #custom>
					<view class="right-custom">
						<uni-icons type="calendar" size="16" color="#28B389"></uni-icons>
						<uni-dateformat :date="Date.now()" format="yyyy.MM.dd" class="date-style"></uni-dateformat>
					</view>
				</template>
			</commonTitle>
			<view class="recommended-context">
				<scroll-view scroll-x="true" show-scrollbar="true">
					<view class="box" v-for="item in randomList" :key="item._id" @click="goPreview(item._id)">
						<image :src="item.smallPicurl" mode="aspectFill"></image>
					</view>
				</scroll-view>
			</view>
		</view>
		<view class="handpick">
			<commonTitle>
				<template #name>
					<text>专题精选</text>
				</template>
				<template #custom>
					<view class="buttom-custom">
						<!-- reLaunch 可以作为跳转到tarbar的界面 -->
						<navigator url="/pages/classify/classify" open-type="reLaunch" class="more">More+</navigator>
					</view>
				</template>
			</commonTitle>
			<view class="handpick-content">
				<themeItem v-for="(item,index) in classifyList" :item="item" :key="item._id"></themeItem>
				<themeItem :isMore="true"></themeItem>
			</view>
		</view>
	</view>
</template>
<script setup>
	import {
		ref
	} from 'vue';
	import {
		onShareAppMessage,
		onShareTimeline,
		onLaunch
	} from "@dcloudio/uni-app"
	import {
		apiGetBanner,
		apiGetNotice,
		apiGetClassify,
		apiGetDayRandomWallPaper
	} from "@/api/apis.js"

	const bannerList = ref([]);
	const randomList = ref([]);
	const noticeList = ref([]);
	const classifyList = ref([]);
	const getBanner = async () => {
		let res = await apiGetBanner();
		bannerList.value = res.records;

	}

	const getDayRandom = async () => {
		let res = await apiGetDayRandomWallPaper();
		randomList.value = res.records
	}

	const getClassify = async () => {
		let res = await apiGetClassify({
			select: true
		});
		classifyList.value = res.records
	}



	//跳转到预览页面
	const goPreview = (id) => {
		uni.setStorageSync("storgClassList", randomList.value);
		uni.navigateTo({
			url: "/pages/preview/preview?id=" + id
		})
	}


	//分享给好友
	onShareAppMessage((e) => {
		console.log("分享....");
		return {
			title: "yuhaowallpaper，好看的手机壁纸",
			path: "/pages/Home/Home"
		}
	})
	//分享朋友圈
	onShareTimeline(() => {
		return {
			title: "yuhaowallpaper，好看的手机壁纸"
		}
	})
	getBanner();
	getDayRandom();
	getClassify();
</script>

<style lang="scss" scoped>
	@import url("../../common/common.scss");

	.right-custom {
		display: flex;
		justify-content: center;
		align-items: center;

		.date-style {
			font-size: 25rpx;
			color: #28B389;
		}
	}

	.handpick {
		margin: 0 30rpx;

		.handpick-content {
			display: grid;
			gap: 15rpx;
			grid-template-columns: repeat(3, 1fr);
		}
	}

	.buttom-custom {
		font-size: 20rpx;
		color: grey;

		.more {
			font-size: 26rpx;
		}
	}

	.main-content {
		.banner {

			width: 750rpx;
			padding: 25rpx 30rpx;

			swiper {
				height: 400rpx;
				margin-bottom: 5px;

				swiper-item {
					height: 100%;
					width: 100%;

					.like {
						height: 100%;
						width: 100%;

						image {
							width: 100%;
						}
					}

				}
			}
		}

		.notice {
			height: 80rpx;
			width: 690rpx;
			border-radius: 80rpx;
			margin: 0 auto;
			display: flex;
			font-size: 30rpx;
			background-color: #f9f9f9;
			line-height: 80rpx;

			.left {
				width: 140rpx;
				height: 100%;
				display: flex;
				justify-content: center;
				align-items: center;

				uni-icons {
					display: inline-block;
					vertical-align: middle;
				}

				.text-notice {
					color: $brand-theme-color;
					font-weight: 600;
					font-size: 28rpx;
				}
			}

			.center {
				flex: 1;

				swiper {
					height: 100%;

					swiper-item {
						height: 100%;
						font-size: 30rpx;
						color: #666;

						navigator {
							overflow: hidden;
							white-space: nowrap;
							text-overflow: ellipsis;
						}
					}

				}
			}

			.right {
				width: 50px;
				display: flex;
				align-items: center;
				justify-content: center;
			}
		}

		.select {
			padding-left: 30rpx;

			.recommended-context {
				width: 720rpx;
				margin-top: 15rpx;

				scroll-view {
					white-space: nowrap;
				}

				.box {
					width: 200rpx;
					height: 300rpx;

					display: inline-block;
					margin-right: 15rpx;

					image {
						width: 100%;
						border-radius: 10rpx;
					}
				}

				.box:last-child {
					margin-right: 30rpx;

				}
			}
		}
	}
</style>